package com.xuecheng.auth.domain.strategy;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.extra.spring.SpringUtil;
import com.xuecheng.auth.domain.model.dto.XcUserDto;
import com.xuecheng.auth.domain.model.entity.XcUser;
import com.xuecheng.auth.domain.model.vo.req.AuthParamsQuery;
import com.xuecheng.auth.domain.service.XcUserService;
import com.xuecheng.base.exception.XueChengPlusException;
import lombok.extern.slf4j.Slf4j;

import java.util.Objects;

/**
 * @Author: LiJunXi
 * @Description:
 * @Date: 2024-09-08  15:38
 */
@Slf4j
public class WxAuthStrategy implements AuthStrategy{

    @Override
    public XcUserDto execute(AuthParamsQuery params) {
        String username = params.getUsername();
        if (Objects.isNull(username)){
            throw new XueChengPlusException("未知错误");
        }
        XcUserService xcUserService = SpringUtil.getBean("xcUserServiceImpl");
        XcUser xcUser = xcUserService.getByUsername(username);

        return BeanUtil.copyProperties(xcUser, XcUserDto.class);
    }

}
